package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.RoadmapParam;
import com.sailfish.springbootdemo.pojo.db1.RoadmapSmallType;
import com.sailfish.springbootdemo.service.db1.RoadmapParamService;
import com.sailfish.springbootdemo.service.db1.RoadmapSmallTypeService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/roadmapParam")
@CrossOrigin
public class RoadmapParamController {

    @Autowired
    private RoadmapParamService roadmapParamService;

    @PostMapping("/getAllRoadmapParam")
    public Result getAllRoadmapParam(String searchValue, Integer roadmapBigTypeId, Integer roadmapSmallTypeId) {
        try {
            return ResultUtil.success(roadmapParamService.getAllRoadmapParam(searchValue, roadmapBigTypeId, roadmapSmallTypeId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deleteRoadmapParam")
    public Result deleteRoadmapParam(Integer roadmapParamId) {
        return roadmapParamService.deleteRoadmapParam(roadmapParamId);
    }

    @PostMapping("/addOrUpdateRoadmapParam")
    public Result addOrUpdateRoadmapParam(String mode, RoadmapParam roadmapParam) {
        return roadmapParamService.addOrUpdateRoadmapParam(mode, roadmapParam);
    }

    @PostMapping("/updateRoadmapRule")
    public Result updateRoadmapRule(Integer roadmapParamId, Integer valueAlgorithmType, String techDeviceParamKeys, Integer ruleAlgorithmType, Integer keyFromType) {
        return roadmapParamService.updateRoadmapRule(roadmapParamId, valueAlgorithmType, techDeviceParamKeys, ruleAlgorithmType, keyFromType);
    }

    @PostMapping("/clearRoadmapParamRule")
    public Result clearRoadmapParamRule(Integer roadmapParamId) {
        return roadmapParamService.clearRoadmapParamRule(roadmapParamId);
    }
}
